//
//  ShowScreenImageView.m
//  MintaiBao
//
//  Created by zhangpei on 15/5/14.
//  Copyright (c) 2015年 zhangpei. All rights reserved.
//

#import "ShowScreenImageView.h"
#import "ViewHelper.h"
#import "UtilityConfig.h"

@interface ShowScreenImageView ()
{
    UIImage *showImage;
}
@end


@implementation ShowScreenImageView

/**
 *  初始化
 */
- (id)initWithFrame:(CGRect)frame withImage:(UIImage *)image
{
    self = [super initWithFrame:frame];
    if (self)
    {
        showImage = image;
        
        [self drawShowScreenImageView:self.bounds];
    }
    return self;
}
/**
 *  创建View
 */
- (void)drawShowScreenImageView:(CGRect)rect
{
    //半透明层
    UIView *translucentView = [[UIView alloc] initWithFrame:WINDOW.bounds];
    
    translucentView.backgroundColor =[UIColor colorWithRed:60.f/255.f green:60.f/255.f blue:60.f/255.f alpha:1.0f];;
    translucentView.alpha = 0.5;
    [self addSubview:translucentView];
    
    CGFloat imageViewWidth = rect.size.width - 40;
    CGFloat imageViewHeight = imageViewWidth * showImage.size.height / showImage.size.width;
    
    UIImageView *imageView = [ViewHelper superView:self withFrame:CGRectMake(0, 0, imageViewWidth, imageViewHeight) withImage:showImage withBackgroundColor:[UIColor clearColor] withUserInteractionEnabled:YES];
    imageView.center = self.center;
    
    [self shakeToShow:imageView];

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self removeFromSuperview];
}

//*************放大过程中出现的缓慢动画*************
- (void) shakeToShow:(UIView*)aView
{
    CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    
    animation.duration = 0.5;
    
    NSMutableArray *values = [NSMutableArray array];
    
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
    //    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
    //    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 1.0)]];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
    animation.values = values;
    [aView.layer addAnimation:animation forKey:nil];
}

@end
